import time

from selenium.webdriver import Keys

import page
from base.base import Base


class PageProductConfig(Base):
    # 点击搜索到的第一个商品
    def page_click_search_after_first_product(self):
        self.base_click_element(page.product_search_after_product)

    # 选择商品套餐
    def page_choose_product_package(self):
        self.base_click_element(page.product_config_package)

    # 选择颜色
    def page_choose_product_color(self):
        self.base_click_element(page.product_config_color)

    # 选择容量
    def page_choose_product_volume(self):
        self.base_click_element(page.product_config_volume)

    # 在数量输入框中输入购买数量
    def page_input_buy_quantity(self, number):
        self.base_keyboard_action(page.product_config_number, Keys.DELETE)
        self.base_in_element_input(page.product_config_number, number)

    # 点击加入购物车按钮
    def page_click_add_to_cart(self):
        self.base_click_element(page.product_cart_btn)

    # 点击关闭弹窗按钮
    def page_click_close_popup(self):
        self.base_click_element(page.product_close_popup)

    # 获得提示信息
    def page_get_config_message_info(self):
        return self.base_get_element_text(page.product_config_message)

    # 切换窗口
    def page_switch_to_window(self, expect_title):
        self.base_switch_to_window(expect_title)

    def page_config(self, expect_title, number):
        self.page_click_search_after_first_product()
        self.page_switch_to_window(expect_title)
        self.page_choose_product_package()
        time.sleep(1)
        self.page_choose_product_color()
        time.sleep(1)
        self.page_choose_product_volume()
        self.page_input_buy_quantity(number)
        self.page_click_add_to_cart()
